Introduction.
A screen with animated text or controls adds a lively, dynamic touch to an application, making it more engaging for both the user and the observer. The Command Button Animation article was the very first post I published on this website.
Another enhancement to screen design was the introduction of 3D headings for forms and reports, using a combination of different fonts, sizes, and styles. Initially, these headings were created manually, which eventually led to the development of the 3D Text Wizards.
You can find the details of 3D Text Styles in the following posts.
The IBM AS/400 (iSeries) screens inspired me to design MS Access interfaces with a dark background, light-shaded data labels, and green text. Although those old text-based screens may seem dated, their clear and highly legible presentation of information remains their greatest strength.
However, when I began designing Access forms in this style, I faced a challenge: the Command Button Animation I had been using wasn’t built for dark backgrounds. This led me to develop a new animation technique—one that complemented the darker design while remaining simple to create and easy to implement without complicated VBA code.
So, here it is for you. I hope you’ll enjoy it as much as I do. We’ll first explore a simple, easy-to-understand version of this method and then move on to a more versatile, reusable routine that can drive the animation on any form with just one or two lines of code.
Command Button Design.
Open a new Form or an existing one.
Select the Footer of the Form. If it is not visible, select Form Header/Footer from the View Menu.
Display the Property Sheet (View -> Properties).
Change the Back Color Property Value to 0.
Select the Command Button Tool from the Toolbox and draw a Command Button in the Footer Section of the Form.
Display the Property Sheet of the Command Button.
Change the Name Property Value to cmdExit and the Caption Property Value to Exit.
Select the Rectangle Tool from the Toolbox and draw a rectangle around the Command Button as shown in the sample design below:
Give a little more gap, between the button and the rectangle at the bottom and the right side than above and left, giving it a feel that the Command Button is in a raised state.
Click on the Rectangle and display its Property Sheet.
Change the Name Property Value to ExitBox and the Visible Property Value to No.
Animating the Command Button
Now, it is time to implement the animation trick. This time, we will not animate the button like we did earlier on the Command Button Animation; instead, the Box around it will be made visible or hidden based on the Mouse movement over the Command Button.
We will track the mouse movement in Code. When the mouse is over the Command Button, the rectangle becomes visible, and when the mouse moves out, it is hidden. When this action is repeated, it will appear as if the command button rises and then returns to its original position. It has a better look and feel in a dark background, rather than remaining flat all the time.
We need to track the Mouse movement at two positions: the On Mouse Move Event of the Command Button and the On Mouse Move Event in the Form Section.
Select the Command Button.
Display the Property Sheet of the Command Button (View -> Properties).
Select [Event Procedure] in the On Mouse Move property and click on the build button (...).
Copy and paste the code given below between the sub-routine skeleton. You can ignore the first and last lines while copying, as these will be present in the Module.
Private Sub cmdExit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Me.ExitBox.Visible = False Then Me.ExitBox.Visible = True End If End Sub
Click anywhere within the Form Footer to select that area, display the Property Sheet, and repeat Step 14 above.
Copy and paste the following code into the empty skeleton of the sub-routine, as you did above:
Private Sub FormFooter_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Me.ExitBox.Visible = True Then Me.ExitBox.Visible = False End If End Sub
Actually, the IF... The statement is not required in the routine. This is introduced to avoid changing the value repeatedly during mouse movements and to avoid flickering.
Trial Run of Animation
Save the Form and open it in Normal view.
Move the Mouse over and out of the Command Button repeatedly, which will give the button a sense of up and down movement every time.
The AnimateFrame() Function
When we implement this animation for several Command Buttons, duplicating the above code everywhere is not good programming. A common routine that can be called with a one-line code, so that it is easy to implement anywhere and for any number of buttons.
Copy and paste the code given below into a Global Module of your database and save it.
Public Function AnimateFrame(ByVal OnOff As Boolean, ByVal x_Box As String) Dim frm As Form, ctrl As Control On Error GoTo AnimateFrame_Err Set frm = Application.Screen.ActiveForm Set ctrl = frm.Controls(x_Box) Select Case OnOff Case False If ctrl.Visible = False Then Exit Function frm.Controls(x_Box).Visible = False Case True If ctrl.Visible = True Then Exit Function frm.Controls(x_Box).Visible = True End Select AnimateFrame_Exit: Exit Function AnimateFrame_Err: Resume AnimateFrame_Exit End Function
Now, we can replace the code we have written earlier with a single-line Code to display and hide the rectangle.
If Me.ExitBox.Visible = False Then Me.ExitBox.Visible = True End If
The above code can be replaced with the statement
AnimateFrame True, "ExitBox"
in the On Mouse Move of the Command Button and
If Me.ExitBox.Visible = True Then Me.ExitBox.Visible = False End If
can be replaced with the statement
AnimateFrame False, "ExitBox"
in the FormFooter_MouseMove event procedure.
- Command Button Animation
- Double Action Command Button
- Colorful Command Buttons
- Transparent Command Button
- Command Button Animation-2
- Creating an Animated Command Button with VBA
- Command Button Color Change on Mouse Move
No comments:
Post a Comment
Comments subject to moderation before publishing.